/* Turska UI library
 * Copyright 2003-2008 Jetro Lauha
 * All rights reserved.
 * Web: http://iki.fi/jetro/ or http://jet.ro
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of EITHER:
 *   (1) The GNU Lesser General Public License as published by the Free
 *       Software Foundation; either version 2.1 of the License, or (at
 *       your option) any later version. The text of the GNU Lesser
 *       General Public License is included with this library in the
 *       file LICENSE-LGPL.txt.
 *   (2) The BSD-style license that is included with this library in
 *       the file LICENSE-BSD.txt.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
 * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
 *
 * $Id: UIGraphicsSDL.cpp,v 1.3 2008/03/27 11:44:27 tonic Exp $
 * $Revision: 1.3 $
 */

#include "SDL.h"
#include "SDL_image.h"
#include "UI.h"


void UIGraphicsSDL::beginRender()
{
}


void UIGraphicsSDL::endRender()
{
}



UIImage * UIGraphicsSDL::loadImage(const char *fileName, UINT32 flags)
{
    SDL_RWops *rw = SDL_RWFromFile(fileName, "rb");
    if (rw == NULL)
        return NULL;
    return loadImage(rw, TRUE, flags);
}


UIImage * UIGraphicsSDL::loadImage(SDL_RWops *source, BOOL freeSource, UINT32 flags)
{
    SDL_Surface *surface;

    surface = loadSurface(source, freeSource);
    if (surface == NULL)
        return NULL;

    UIImage *res = createImage(surface, flags);
    //SDL_FreeSurface(surface);

    return res;
}


SDL_Surface * UIGraphicsSDL::loadSurface(const char *fileName)
{
    SDL_RWops *rw = SDL_RWFromFile(fileName, "rb");
    if (rw == NULL)
        return NULL;
    return loadSurface(rw, TRUE);
}


SDL_Surface * UIGraphicsSDL::loadSurface(SDL_RWops *source, BOOL deleteSource)
{
    return IMG_Load_RW(source, deleteSource ? 1 : 0);
}


UIImage * UIGraphicsSDL::createImage(SDL_Surface *surface, UINT32 flags
                                     /*, UIRectangle *sourceRect*/)
{
    if (surface == NULL)
        return NULL;

    return new UIImageSDL(surface, flags);
}
